(function($){
	
    $(function(){
    	//用户信息展示
        $('#awardUserInfo').dialog({
            autoOpen: false,
            height: 300,
            width: 560,
            modal: true,
            buttons: {
                '确定': function(){
                    $(this).dialog('close');
                }
            }
        });
        //修改非虚拟物品个数
        $('#changeNoVNum').dialog({
            autoOpen: false,
            height: 300,
            width: 560,
            modal: true,
            buttons: {
                '确定': function(){
                	var newcurrNum = $('#currNum').val();
                	var awardId  = $('#noVawardId').val();
                	var activeId  = $('#activeId').val();
                	if(newcurrNum!==null&&newcurrNum!==undefined&& newcurrNum!==''&& !isNaN(newcurrNum)){
                		//调用ajax方法
                		$.ajax({
                			type:"POST",
                			url:ctx+"/award/ajaxChangeNOVirtualNum.do",
                			data:"awardId="+awardId+"&currNum="+newcurrNum+"&activeId="+activeId,
                			success: function(msg){
                				 if(msg.startWith("error:")){
                					 showTips("出错了:"+msg.substring(6,msg.length)); 
                				 }else{
                					 showTips("执行成功",function(){window.location.reload();},
                							 function(){
                						 window.location.reload();
                					 }
                							 );
                				 }
                			}
                		});
                	}else{
                		$('.validate-tips').text('请输入数字');
                	}
                	
                }
            }
        });
		//用户信息链接点击
		$('.award-user-info-link').click(function(e){
			e.preventDefault();
			//根据点击获取信息填充$('#awardUserInfo')然后显示
			$('#diaName').text($(this).attr('realName'));
			$('#diaPhone').text($(this).attr('phone'));
			$('#diaQQ').text($(this).attr('qq'));
			$('#diaAddress').text($(this).attr('address'));
			$('#awardUserInfo').dialog('open');
		});
		
		//修改奖品当前数量
		$('#changeNum').click(function(e){
			$('#changeNoVNum').dialog('open');
		})
		
		//全选
		$('.checked-all').click(function () {
			var _cbs = $(this).closest('.content').find('table input:checkbox');
			_cbs.prop('checked', this.checked);
		});
		
		$('.content table input:checkbox').click(function() {
			var _content = $(this).closest('.content');
			var _cbs = _content.find('table input:checkbox');
			_content.find('input:checkbox').last().prop('checked' , _cbs.length === _cbs.filter(':checked').length ? true : false);
		});
		//虚拟物品删除
		$('.is-delete').click(function(){
			//取参数
			var array = checkedToArray('awdid');
			var awardId  = $('#awardId').val();
			var activeId  = $('#activeId').val();
			//提出异步请求
			$.ajax({
				url: ctx+'/award/ajaxRemoveVirtual.do',
				type: "post",
				data: {
					chks:array.toString(),
					awardId:awardId,
					activeId:activeId
				},
				success: function(msg) {
					if(msg.startWith("error:")){
						showTips("出错了:"+msg.substring(6,msg.length));
			   			}else{
			   				showTips("执行成功",function(){window.location.reload();});
			   				
			   			}
				}
			});
		});
    });
    	
})(jQuery);